package com.john.springboot.controller;

import java.util.List;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.john.springboot.entity.User;
import com.john.springboot.service.IUserService;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userServiceImpl;
	
    
    /**
     * 分页 PAGE
     */
    @GetMapping("/all")
    public List<User> all() {
        return userServiceImpl.selectListBySQL();
    }

    /**
     * AR 部分测试
     */
    @RequestMapping("/getUserById/{id}")
    public User getUserById(@PathVariable("id") String id) {
    	 return userServiceImpl.getUserById(Long.valueOf(id));
    }

    /**
     * 增删改查 CRUD
     */
    @RequestMapping("/update/{id}")
    public User update(@PathVariable("id") String id) {
    	User user=userServiceImpl.getUserById(Long.valueOf(id));
    	user.setName("testupdate");
    	try {
			return userServiceImpl.update(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return null;
    }

   
}
